import java.util.Scanner;

//链表相加
public class test2 {
    static class ListNode{
        public int data;
        public ListNode next;
        public ListNode(int data){
            this.data = data;
            this.next=null;
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();//链表1的节点数
        int m = scanner.nextInt();//链表2的节点数

        //链表1
        ListNode listNode1 =null;
        ListNode cur1 =null;
        for (int i = 0; i < n; i++) {
            ListNode node = new ListNode(scanner.nextInt());
            if(listNode1==null){
                listNode1=node;
                cur1 = node;
            }else {
                cur1.next = node;
                cur1=node;
            }
        }

        //链表2
        ListNode listNode2 = null;
        ListNode cur2 = null;
        for (int i = 0; i <m ; i++) {
            ListNode node = new ListNode(scanner.nextInt());
            if (listNode2==null){
                listNode2=node;
                cur2=node;
            }else {
                cur2.next=node;
                cur2=node;
            }
        }

        /*solve(listNode1);
        System.out.println();
        solve(listNode2);
        System.out.println();

        //链表翻转再翻转!
        solve(changeNode(listNode1));*/

        solve(addInList(listNode1,listNode2));
    }
    public static void solve(ListNode node){
        ListNode cur = node;
        while (true){
            System.out.print(cur.data+" ");
            cur=cur.next;
            if (cur==null){
                break;
            }
        }
    }

    public static ListNode changeNode(ListNode node){
        if (node==null){
            return null;
        }
        ListNode curNode = node;
        ListNode newNode = null;
        while (curNode!=null){
            ListNode flag = curNode.next;
            curNode.next = newNode;
            newNode=curNode;
            curNode=flag;
        }

        return newNode;//返回新的头节点
    }

    public static ListNode addInList (ListNode head1, ListNode head2) {
        if(head1==null){
            return head1;
        }
        if (head2==null){
            return head2;
        }
        head1=changeNode(head1);
        head2=changeNode(head2);

        ListNode result = null;
        ListNode cur = null;
        int count = 0;//记录要进位的个数
        while (head1!=null||head2!=null||count!=0){
            int num1 = head1==null?0:head1.data;
            int num2 = head2==null?0:head2.data;
            int res = num1+num2+count;
            count = res/10;
            res%=10;
            if (result==null){
                result = new ListNode(res);
                cur=result;
            }else{
                cur.next = new ListNode(res);
                cur = cur.next;
            }
            //向后移动
            if (head1!=null){
                head1=head1.next;
            }
            if (head2!=null){
                head2=head2.next;
            }
        }
        return changeNode(result);
    }
}
